package com.lin.controller;

import com.lin.annotation.MyLog;
import com.lin.pojo.Wares;
import com.lin.pojo.WaresOrder;
import com.lin.services.DamageReportService;
import com.lin.services.WaresService;
import com.lin.utils.PageUnit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * ClassName DamageReportController
 * Package com.lin.controller
 *
 * @author hellcat
 * Date 2020/3/24
 * Description:报损报表管理
 * 🐾
 */
@Controller
@RequestMapping("damageReport")
public class DamageReportController {
    @Autowired
    private DamageReportService damageReportService;


    @MyLog("查看报损报表")
    @RequiresPermissions("report:damageReport:list")
    @RequestMapping(value = "/toDamageReport", method = RequestMethod.GET)
    public String toDamageReport(HttpServletRequest request) {
        request.setAttribute("ddId", "DamageReport");
        return "damageReportMain";
    }

    @RequiresPermissions("report:damageReport:list")
    @ResponseBody
    @RequestMapping(value = "/getDamageReport", method = RequestMethod.POST)
    public Map<String, Object> getDamageReport(HttpServletRequest request) {
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        String searchDate = request.getParameter("searchDate");
        String searchWaresId = request.getParameter("searchWaresId");
        List<WaresOrder> list = damageReportService.getDamageReport(searchDate, searchWaresId);
        return PageUnit.Page(list, page, limit);
    }

    @RequiresPermissions("report:damageReport:list")
    @ResponseBody
    @RequestMapping(value = "/getChartsData", method = RequestMethod.POST)
    public Map<String, Object> getChartsData(HttpServletRequest request) {
        String date = request.getParameter("date");
        return damageReportService.getChartsData(date);
    }
}
